class Student:
    def __init__(self, name, age, grades):
        self.name = name
        self.age = age
        self.grades = grades
    def get_average(self):
        """计算平均成绩"""
        return sum(self.grades.values()) / len(self.grades) if self.grade else 0

    def  display_info(self):
        """显示学生基本信息"""
        print(f"Student: {self.name}, Age: {self.age}")

class GraduateStudent(Student):

    def __init__(self, name, age, grades, advisor):

        super().__init__(name, age, grades)
        self.advisor = advisor
        self.thesis_title = None

    def set_thesis(self, title):
        """设置论文标题"""
        self.thesis_title = title


    def display_info(self):
        """重写父类的显示方法，增加研究生特有信息"""
        super().display_info()
        print(f"Advisor:{self.advisor}")
        if self.thesis_title:
            print(f"Thesis: {self.thesis_title}")

    def print_grades(self):
        """打印详细成绩单（新增方法）"""
        print(f"\nGrade Report for {self.name}:")
        for subject, grade in self.grades.item():
            print(f"{subject.capitalize():.1f}")


undergrad = Student("ALice",20,{'math': 88, 'english': 92, 'history': 85 })
undergrad.display_info()

grad = GraduateStudent("Bob",25,
                       {'math': 95, 'english': 90, 'research_method': 88},
                       "Dr.Smith")

grad.set_thesis("Machine Learning Applications in Biology")

grad.display_info()

grad.print_grades()

print(f"\nIs grad a Student? {isinstance(grad, Student)}")
print(f"Is grad a GraduateStudent? {isinstance(grad, GraduateStudent)}")
print(f"Is undergrad a GraduateStudent? {isinstance(undergrad, GraduateStudent)}")

class GraduateStudent(Student):
    __minimum_gpa = 3.0

    @classmethod
    def set_minimum_gpa(cls, new_gpa):
        """类方法：修改最低GPA要求"""
        cls.__minimum_gpa = new_gpa

    def __init__(self, name, age, grades, advisor):
        super().__init__(name, age, grades)
        self.__thesis_title = None
    def get_advisor(self):
        """获取导师名称（封装私有属性）"""
        return self.__advisor
    def set_thesis(self, title):
        self.__thesis_title = title

    def can_graduate(self):
        """检查是否符合毕业条件"""
        return self.get_average() >= self.__minimum_gpa

    def display_info(self):
        super().display_info()
        print(f"Advisor: {self.__advisor}")
        if self.__thesis_title:
            print(f"Thesis: {self.__thesis_title}")
        print(f"Graduation Status: {'Eligible' if self.can_graduate() else'Not Eligible'}")

phd_student = GraduateStudent("Carol",28,
                             {'math': 95, 'research': 90, 'stats': 80},
                             "Dr. Johnson")
phd_student.set_thesis("Deep Learning in Medical Imaging")
phd_student.display_info()

GraduateStudent.set_minimum_gpa(3.5)
print(f"\nAfter changing requirement:")
phd_student.display_info()